import requests
from pprint import pprint
import os

# load from vault
import vault2env
config = vault2env.load("GTX")

headers = {
    'User-Agent': 'DNSPOD-CR-Client/1.0(azhao@foxmail.com)',
}

login_token = "{0},{1}".format(config['DNSPOD.ID'], config['DNSPOD.TOKEN'])

payload = {
  "login_token": login_token,
  "format": "json",
}

def get_domain_list(payload):
  r = requests.post("https://dnsapi.cn/Domain.List", headers=headers, data=payload)
  domains = r.json()['domains']
  return domains

domains = get_domain_list(payload)
for domain in domains:
  print(domain['id'], domain['name'])

def get_record_list(payload):
  r = requests.post("https://dnsapi.cn/Record.List", headers=headers, data=payload)
  records = r.json()['records']
  return records

data = payload.copy()
data['domain_id'] = '76474470'
records = get_record_list(data)

for record in records:
  print(record['id'],"\t", record['name'],'\t',record['value'])